package com.wlz;

import com.sun.net.httpserver.HttpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(WlzServer.class)
@EnableConfigurationProperties(WlzServerProperties.class)
public class WlzServerAutoConfiguration {

    @Autowired
    private WlzServerProperties properties;

    @Bean
    @ConditionalOnClass(HttpServer.class)
    @ConditionalOnProperty(prefix = "wlz.server", value = "enabled",havingValue = "true")
    WlzServer wlzServer (){
        return new WlzServer(properties.getPort());
    }

}